package com.ocom.payconfig.controller;

import com.github.pagehelper.PageInfo;
import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.CouponsDataExportRequest;
import com.ocom.common.request.payconfig.SubsidyDataRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.common.vo.payconfig.*;
import com.ocom.common.vo.webapi.ExcelCouponsVoucherListVo;
import com.ocom.payconfig.service.VoucherDataService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class VoucherDataController {

    @Resource
    private VoucherDataService voucherDataService;

    /***
     * 添加赠券数据
     * @param addCoupons
     * @return
     */
    @PostMapping(PayConfigUrl.Url_addCouponsData)
    public Result addCouponsData(@RequestBody AddCouponsDataVo addCoupons) {
        return voucherDataService.addCouponsData(addCoupons.getComId(),addCoupons);
    }

    /***
     * 赠券数据
     * @param couponsDataVo
     * @return
     */
    @PostMapping(PayConfigUrl.Url_voucherList)
    public Result couponsDataList(@RequestBody @Valid CouponsDataListVo couponsDataVo) {
        return ResultUtil.success(voucherDataService.couponsDataList(couponsDataVo.getComId(),couponsDataVo));
    }

    /**
     * 修改赠券数量
     * @param request
     * @return
     */
    @PostMapping(PayConfigUrl.Url_changeCouponsNumber)
    public Result changeCouponsNumber(@RequestBody @Valid ChangeCouponsNumberVo request){
        return ResultUtil.success(voucherDataService.changeCouponsNumber(request.getComId(), request));
    }

    @PostMapping(PayConfigUrl.Url_breakCoupons)
    public Result breakCoupons(@RequestBody @Valid BreakCouponsVo request){
        return ResultUtil.success(voucherDataService.breakCoupons(request.getComId(),request));
    }
//    @PostMapping(PayConfigUrl.Url_grantCoupons)
//    public Result grantCoupons(@RequestBody @Valid GrantCouponsVo request){
//        return ResultUtil.success(voucherDataService.grantCoupons(request.getComId(),request));
//    }
    @PostMapping(PayConfigUrl.Url_couponsNumber)
    public CouponsNumberRVo couponsNumber(@RequestParam("comId") Long comId, @RequestParam("orderNo") String orderNo){
        return voucherDataService.couponsNumber(comId,orderNo);
    }

    @PostMapping(PayConfigUrl.url_importCouponsVoucher)
    public Result importCouponsVoucher(@RequestBody ExcelCouponsVoucherListVo excelAddCouponsVo){

        return ResultUtil.success(voucherDataService.importCouponsVoucher(excelAddCouponsVo.getComId(),excelAddCouponsVo));
    }

    @PostMapping(PayConfigUrl.Url_sendMealCouponByPerson)
    public Result sendMealCouponByPerson(@RequestBody SendMealCouponVo request){
        return voucherDataService.sendMealCouponByPerson(request.getComId(), request);
    }
    @PostMapping(PayConfigUrl.Url_deleteVoucherDataByIds)
    public Result deleteVoucherDataByIds(@RequestBody IdsVo ids){
        return voucherDataService.deleteByIds(ids.getComId(), ids.getIds());
    }

    @PostMapping(PayConfigUrl.Url_couponsDataList)
    public Result couponsDataList(@RequestBody CouponsDataExportRequest request){
        return ResultUtil.success(voucherDataService.selectCouponsDataList(request.getComId(), request));
    }

    @PostMapping(PayConfigUrl.URL_getPackagePayBySms)
    public Result getPackagePayBySms(@RequestParam("comId") Long comId, @RequestParam("pId") Long pId){
        return ResultUtil.success(voucherDataService.getPackagePayBySms(comId, pId));
    }

}
